package com.company.cloud.art.modules.mgr.controller;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.company.cloud.art.modules.api.request.ArtistAddReq;
import com.company.cloud.art.modules.api.request.ArtistQueryReq;
import com.company.cloud.art.modules.api.request.ArtistUpdateReq;
import com.company.cloud.art.modules.api.response.Artist;
import com.company.cloud.art.modules.api.response.ArtistQueryResp;
import com.company.cloud.art.modules.base.entity.ArtistInfo;
import com.company.cloud.art.modules.cache.utils.ArtNoUtils;
import com.company.cloud.art.modules.mgr.service.ActArtistMgrService;
import com.company.cloud.common.asserts.ValidatorUtils;
import com.company.cloud.common.auth.annotation.Authc;
import com.company.cloud.common.auth.annotation.StaffLogc;
import com.company.cloud.common.bean.BaseResult;
import com.company.cloud.common.bean.LoginSimpleUserInfo;
import com.company.cloud.common.bean.LoginUserInfo;
import com.company.cloud.common.exception.BusinessException;
import com.company.cloud.common.log.annotation.SysLog;
import com.company.cloud.common.utils.AuthContextUtils;
import com.company.cloud.common.utils.CheckUtils;
import com.company.cloud.common.utils.StrSplitUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

@Authc
@RestController
@RequestMapping("/mgr/art/artist")
@Api(tags="ART_Mgr_艺术家管理")
public class ArtistMgrController {


    @Autowired
    private ActArtistMgrService actArtistMgrService;


    @PostMapping("/query")
    @ApiOperation(value="查询", response= Artist.class)
    public BaseResult query(@RequestBody ArtistQueryReq params) {
        ArtistQueryResp data= actArtistMgrService.artistQuery(params);
        return BaseResult.ok(data);
    }

    @GetMapping("/get")
    @ApiOperation(value="详情",response=Artist.class)
    public BaseResult get(@RequestParam("artistNo")String artistNo) {
        Artist data= actArtistMgrService.artistInfo(artistNo);
        return BaseResult.ok(data);
    }

    @PostMapping("/save")
    @ApiOperation(value="新增",response = BaseResult.class)
    @StaffLogc(title = "新增艺术家", action = "新增艺术家", actionAdo = "艺术家管理")
    public BaseResult save(@RequestBody ArtistAddReq params) {
        LoginSimpleUserInfo userInfo= AuthContextUtils.getUser();
        if("PTC".equals(userInfo.getCompanyNo())){
            if(StrUtil.isEmpty(params.getCompanyNo())){
                params.setCompanyNo(userInfo.getCompanyNo());
            }
        }else{
            params.setCompanyNo(userInfo.getCompanyNo());
        }
        actArtistMgrService.artistAdd(params,userInfo);
        return BaseResult.ok();
    }

    @PostMapping("/update")
    @ApiOperation(value="修改",response = BaseResult.class)
    @StaffLogc(title = "修改艺术家", action = "修改艺术家", actionAdo = "艺术家管理")
    public BaseResult update(@RequestBody ArtistUpdateReq params) {
        LoginSimpleUserInfo userInfo= AuthContextUtils.getUser();
        actArtistMgrService.artistUpdate(params,userInfo);
        return BaseResult.ok();
    }

    @GetMapping("/delete")
    @ApiOperation(value="删除")
    @StaffLogc(title = "删除艺术家", action = "删除艺术家", actionAdo = "艺术家管理")
    public BaseResult delete(@RequestParam("artistNo")String artistNo) {
        LoginSimpleUserInfo userInfo= AuthContextUtils.getUser();
        actArtistMgrService.artistDel(artistNo,userInfo);
        return BaseResult.ok();
    }
}
